package CH02链表结构.LeetCode链表;

public class LC2181 {
    public ListNode mergeNodes(ListNode head) {
        ListNode dummy = new ListNode(0);
        ListNode L = head;
        ListNode R = L.next;
        ListNode rear = dummy;
        int sum = 0;
        while (R != null) {
            if (R.val == 0) {
                ListNode n = new ListNode(sum);
                sum = 0;
                L = R;
                R = L.next;
                rear.next = n;
                rear = n;
            } else {
                sum += R.val;
                R = R.next;
            }
        }
        return dummy.next;
    }
}